package com.itheima.controller;
import com.itheima.domain.SmsHomeNewProduct;
import com.itheima.manager.SmsHomeNewProductManager;
import com.itheima.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {

    @Autowired
    SmsHomeNewProductManager smsHomeNewProductManager;

    @PostMapping("/create")
    public R addNewProduct(@RequestBody List<SmsHomeNewProduct> newProducts){
        return smsHomeNewProductManager.addNewProduct(newProducts);

    }

    @PostMapping("/delete")
    public R deleteNewProduct(@RequestParam("ids") List<Long> ids) {
        return smsHomeNewProductManager.deleteBrand(ids);

    }


    @GetMapping("/list")
    public R findByPage(Integer pageNum, Integer pageSize,String productName,Integer recommendStatus){
        return smsHomeNewProductManager.findByPage(pageNum,pageSize,productName,recommendStatus);
    }

    @PostMapping("/update/recommendStatus")
    public R updateNewProduct(@RequestParam("ids") List<Long> ids,@RequestParam("recommendStatus") Integer recommendStatus){
        return smsHomeNewProductManager.updateNewProduct(ids,recommendStatus);

    }

    @PostMapping("/update/sort/{id}")
    public R updatesortNewProduct(@PathVariable("id") Long id,@RequestParam(required = false) Integer sort){
        return smsHomeNewProductManager.updatesortNewProduct(id,sort);

    }
}
